// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from '@/App'
import router from '@/router'
import store from '@/store/index'
import api from '@/utils/api'
import swal from 'sweetalert2'

Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {
  store.dispatch("onLoading", true);
  next()
});
router.afterEach((to, from) => {
  setTimeout(function () {
    store.dispatch("onLoading", false);
    store.dispatch("Get", {
      url: api.isLogin
    }).then(function (res) {
      if (res.data !== true && router.currentRoute.name !== 'login') {
        localStorage.clear("userinfo");
        swal({
          title: "您还未登录，请先登录",
          text: "2秒后自动关闭。",
          timer: 2000,
          showConfirmButton: false
        }).then(function (result) {
          router.push({ name: 'login'})
        });

      }
    })


  }, 300)
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
});
